using System;

namespace Multiplicity {
    public static class Throw {

        public static void IfIsNull(object obj) {
            if (obj == null) Throw.ArgumentNullException();
        }
        public static void IfIsNull(object obj, string format, params object[] args) {
            if (obj == null) Throw.ArgumentNullException(format, args);
        }
        public static void IfIsNullOrEmpty(Array array) {
            if (array == null || array.Length == 0) {
                Throw.ArgumentNullException();
            }
        }
        public static void IfIsNullOrEmpty(string str, string format, params object[] args) {
            if (str == null || str.Length == 0) {
                Throw.ArgumentNullException(format, args);
            }
        }
        public static void IfIsNotDefined(Enum e) {
            Throw.ArgumentOutOfRangeExceptionIf(!Enum.IsDefined(e.GetType(), e), "Value 0x{0:x} is not valid for {1}", e,  e.GetType().Name);
        }

        public static void ArgumentException(string format, params object[] args) {
            Throw.ArgumentException(string.Empty, format, args);
        }
        public static void ArgumentExceptionIf(bool condition, string format, params object[] args) {
            if (condition) {
                Throw.ArgumentException(format, args);
            }
        }
        public static void ArgumentException(string paramName, string format, params object[] args) {
            throw new ArgumentException(string.Format(format, args), paramName);
        }
        public static void ArgumentNullException() {
            throw new ArgumentNullException();
        }
        public static void ArgumentNullException(string format, params object[] args) {
            throw new ArgumentNullException(string.Format(format, args));
        }
        public static void ArgumentOutOfRangeException() {
            throw new ArgumentOutOfRangeException();
        }
        public static void ArgumentOutOfRangeException(string format, params object[] args) {
            throw new ArgumentOutOfRangeException(string.Format(format, args));
        }

        public static void ArgumentOutOfRangeExceptionIf(bool condition) {
            if (condition) {
                Throw.ArgumentOutOfRangeException();
            }
        }
        public static void ArgumentOutOfRangeExceptionIf(bool condition, string format, params object[] args) {
            if (condition) {
                Throw.ArgumentOutOfRangeException(string.Format(format, args));
            }
        }

        public static void InvalidOperationException() {
            throw new InvalidOperationException();
        }

        public static void NotSupportedException() {
            throw new NotSupportedException();
        }
        public static void NotSupportedException(string format, params object[] args) {
            throw new NotSupportedException(string.Format(format, args));
        }

        public static void ToDoException(string format, params object[] args) {
            System.Diagnostics.Debug.Write("TODO: ");
            System.Diagnostics.Debug.WriteLine(string.Format(format, args));
        }

    }






}
